<?php

namespace IDock\Insurance\MACN\Response;

use IDock\Http\Response;
use IDock\Printer\ProposalRecallPrinter;
use IDock\Printer\ValidateCarCodePrinter;

class ValidateCarResponse extends AllMACNResponse
{

    public function resolve(): Response
    {
        $proposalRecallPrinter = new ProposalRecallPrinter();
        $this->printer = $proposalRecallPrinter;
        $body = $this->getBody();
        $body = iconv('UTF-8','GBK',$body);
        if ($body) {
            libxml_disable_entity_loader();
            $body = simplexml_load_string($body);
            $body = $this->objectToArray($body);
            $errorCode = $body['head']['statusCode'] ?? '';
            if ($errorCode != '000000') {
                $this->setError($body['head']['description'] ?? '未知错误或无错误提示');
                return  $this;
            }

            $this->setBody($body['body'] ?? '');
        }

        return $this;
    }

    public function printerInit(): Response
    {
        $this->printer = new ValidateCarCodePrinter();

        $this->printer->code = $this->get('baseInfo')['checkcarcode'] ?? '';

        return  $this;
    }
}
